//// Replication code for Rural Identity as a Contributing Factor to Anti-Intellectualism in the U.S.
//// Kristin Lunz Trujillo
//// lunzx007@umn.edu ; ktrujillo@hks.harvard.edu



//////// PART 1 //////////////////////////////////////////////////////
//////// Lucid correlational  //////////////////////////////////////////
// USE "lucid_aug_polbev.dta"  for this PART 1 section /////////////////////////////////////////////////////////

///////////////////////// RUCA coding

// initial RUCA recode (var = ruca_rural) versus raw merged ruca codes (ruca)
tab ruca ruca_rural
tab ruca_rural
// alternative RUCA recode (var = ruca_rural_second) versus raw merged ruca codes (ruca)
tab ruca ruca_rural_second
tab ruca_rural_second
/// compare initial and alternative RUCA codes
tab ruca_rural ruca_rural_second
corr ruca_rural ruca_rural_second

//// NOTE: Coding for the following is background information on how the scales were created.
/////////////////////// Rural identity strength (var = "rasocid")
///egen rasocidx = rmean(rasocid1 rasocid2 rasocid3 rasocid4 rasocid5)
///tab rasocidx
///gen rasocid = (rasocidx-1)/4
///replace rasocid = (-rasocid)+1
///tab rasocid

///////////////////// Metro identity strength (var = "masocid")
///egen masocidx = rmean(masocid1 masocid2 masocid3 masocid4 masocid5)
///tab masocidx
///gen masocid = (masocidx-1)/4
///replace masocid = (-masocid)+1
///tab masocid

//////////////////// Anti-Intellectualism (var = "pop_exp")
///corr pop_ex1 pop_ex2 pop_ex3rev
///gen pop_ex3 = -(pop_ex3rev)+8
///egen pop_expx = rmean(pop_ex1 pop_ex2 pop_ex3)
///gen pop_exp = (pop_expx-1)/6
///tab pop_expx


corr pop_exp rasocid
corr pop_exp masocid


////////////////// Table 2
reg pop_exp rasocid [pweight=weight]
est store t2_1
reg pop_exp rasocid pid ideo age gen black hisp evang inc edu [pweight=weight]
est store t2_2
reg pop_exp ruca_rural [pweight=weight]
est store t2_3
reg pop_exp ruca_rural pid ideo age gen black hisp evang inc edu [pweight=weight]
est store t2_4
reg pop_exp masocid [pweight=weight]
est store t2_5
reg pop_exp masocid pid ideo age gen black hisp evang inc edu [pweight=weight]
est store t2_6

/// Figure 1
reg pop_exp rasocid [pweight=weight]
margins, at(rasocid =(0 1))
marginsplot, scheme(s1mono) name(rasocid1,replace) title("") xtitle("Rural Social Identity") ytitle("Anti-Intellectualism") yscale(range(0(.1) 1)) ylabel(#5, grid) plotopts(msize(tiny))
/// NOTE: I then manually (using the graph editor) changed the y-axis scale to go from 0 to 1 and by increments of .1, and I changed the graph size width to 3.5.


//// Figure 2
/// Note: Figure 2 is based on the model in Table A3 of the appendix. Here is the Table regression:
reg pop_exp c.rasocid##c.pid ideo age gen black hisp evang inc edu [pweight=weight]
est store ta3_1
margins, at(rasocid=(0 1) pid=(0 1))
marginsplot, scheme(s1mono) name(rasocid1,replace) title("") xtitle("Rural Social Identity") ytitle("Anti-Intellectualism") yscale(range(0(.1) 1)) ylabel(#5, grid) plotopts(msize(tiny))
/// NOTE: I then manually (using the graph editor) changed the y-axis scale to go from 0 to 1 and by increments of .1, and I changed the graph size width to 3.5. I also changed the legend so it says "Strong Democrat" instead of "pid=0" and "Strong Republican" instead of "pid=1"


/// Table A3a
reg pop_exp ruca_rural_second [pweight=weight]
est store ta3a_1
reg pop_exp ruca_rural_second pid ideo age gen black hisp evang inc edu [pweight=weight]
est store ta3a_2






//////// PART 2 //////////////////////////////////////////////////////
//////// ANES  //////////////////////////////////////////
// USE "anes2019_polbev.dta" /////////////////////////////////////////////////////////

////// Rural residency (var = "rural")
gen rural = 0
replace rural = 1 if liveurban == 1
replace rural = 2 if liveurban == 2

////// Rural identity (var = "ruralid_use")
tab placeid1a
gen feelbelong_rural1 = .
replace feelbelong_rural1 = 1 if placeid1a > 2
replace feelbelong_rural1 = 0 if placeid1a < 3
tab placeid1b
gen feelbelong_rural2 = .
replace feelbelong_rural2 = 1 if placeid1b > 2
replace feelbelong_rural2 = 0 if placeid1b < 3
gen ruralid_use = .
replace ruralid_use = feelbelongrural1 if feelbelong_rural1 != .
replace ruralid_use = feelbelongrural2 if feelbelong_rural2 != .
tab ruralid_use


//// Table 3
tab rural ruralid_use
/// NOTE: Statistics above Table 3 are as follows:
display 904/(904+328)
display 481/(481+1452)
display 481/(481+904)


///////// Anti-Intellectualism (variable = anti_exp)
tab experts
tab science
tab exphelp
gen antiexp1 = (-experts+5)/4
tab antiexp1
gen antiexp2 = (-science+5)/4
tab antiexp2
gen antiexp3 = (-exphelp+5)/4
tab antiexp3
egen anti_exp = rmean(antiexp1 antiexp2 antiexp3)
alpha(antiexp1 antiexp2 antiexp3)


/// Table 4
reg anti_exp ruralid_use pid_use ideo age gender black hisp bornagain inc edu i.region [pweight=weight]
est store t4_1
reg anti_exp rural pid_use ideo age gender black hisp bornagain inc edu i.region [pweight=weight]
est store t4_2
reg anti_exp i.ruralid_use##i.rural pid_use ideo age gender black hisp bornagain inc edu i.region [pweight=weight]
est store t4_3
margins, at(ruralid_use=(0 1) rural=(0 1))
marginsplot
reg anti_exp i.ruralid_use##c.pid_use ideo age gender black hisp bornagain inc edu i.region [pweight=weight]
est store t4_4
margins, at(ruralid_use=(0 1) pid_use=(0 1))
marginsplot


/////Figure 3
reg anti_exp ruralid_use pid_use ideo age gender inc edu bornagain i.region [pweight=weight]
margins, at(ruralid_use=(0 1))
marginsplot, scheme(s1mono) name(rurid1,replace) title("") xtitle("Rural Social ID") ytitle("Anti-Intellectualism") yscale(range(0 1)) ylabel(#5, grid) plotopts(msize(tiny))
est store x1
margins, at( ideo=(0 1))
marginsplot, scheme(s1mono)  name(ideo1,replace) title("") xtitle("Symbolic Ideology") ytitle("") yscale(range(0 1)) ylabel(#5, grid) plotopts(msize(tiny))
margins, at(pid_use=(0 1)) saving(file3, replace)
marginsplot, scheme(s1mono)  name(pid1,replace) title("") xtitle("Party ID") ytitle("Anti-Intellectualism") yscale(range(0 1)) ylabel(#5, grid) plotopts(msize(tiny))
margins, at(edu=(0 1))  saving(file4, replace)
marginsplot, scheme(s1mono)  name(edu1,replace) title("") xtitle("Edu. Level") ytitle("") yscale(range(0 1)) ylabel(#5, grid) plotopts(msize(tiny))
gr combine rurid1 ideo1 pid1 edu1, scheme(s1mono)






//////// PART 3 //////////////////////////////////////////////////////
//////// Initial Experiment  //////////////////////////////////////////
// USE "experiment_initial_polbev.dta" /////////////////////////////////////////////////////////

/// variable for experiment = "cond"

/// Rural residency (self id)
gen liverural = 0
replace liverural = 1 if lq2 == 4
gen bothrural = 0
replace bothrural = 1 if lq2 == 4
replace bothrural = 1 if lq1 == 4


//// Anti-Intellectualism
tab pop_exp1
gen popexp1 = (pop_exp1-1)/6
tab pop_exp2
gen popexp2 = (pop_exp2-1)/6
tab pop_exp3r
gen popexp3 = (-pop_exp3r+7)/6
corr popexp1 popexp2 popexp3
alpha popexp1 popexp2 popexp3
egen popexp = rmean(popexp1 popexp2 popexp3)
tab popexp



//// Figure 4:
tab cond bothrural
by cond, sort: tabstat popexp if bothrural==1, stat(mean sd)
by cond, sort: tabstat popexp if bothrural==0, stat(mean sd)
/// RURAL control UNWEIGHT :::: .33 / .22 n = 35
/// RURAL treat UNWEIGHT ::::: .45 / .21  n = 19
/// NONRURAL control UNWEIGHT ::: .41 / .19 n = 135
/// NONRURAL treat UNWEIGHT ::: .36 / .21 n = 145


/// ttests
ttest popexp if bothrural==1, by(cond)
ttest popexp if bothrural==0, by(cond)









//////// PART 4 //////////////////////////////////////////////////////
//////// Replication Experiment  //////////////////////////////////////////
// USE "experiment_replication_polbev.dta" /////////////////////////////////////////////////////////

/// Anti-Intellectualism: randomly assigned first
tab antiint_1_1
gen ai11 = .
replace ai11 = . if antiint_1_1 == "NA"
replace ai11 = 0 if antiint_1_1 == "Strongly disagree"
replace ai11 = 1 if antiint_1_1 == "Disagree"
replace ai11 = 2 if antiint_1_1 == "Slightly disagree"
replace ai11 = 3 if antiint_1_1 == "Neither agree nor disagree"
replace ai11 = 4 if antiint_1_1 == "Slightly agree"
replace ai11 = 5 if antiint_1_1 == "Agree"
replace ai11 = 6 if antiint_1_1 == "Strongly agree"
tab antiint_1_2
gen ai12 = .
replace ai12 = . if antiint_1_2 == "NA"
replace ai12 = 0 if antiint_1_2 == "Strongly disagree"
replace ai12 = 1 if antiint_1_2 == "Disagree"
replace ai12 = 2 if antiint_1_2 == "Slightly disagree"
replace ai12 = 3 if antiint_1_2 == "Neither agree nor disagree"
replace ai12 = 4 if antiint_1_2 == "Slightly agree"
replace ai12 = 5 if antiint_1_2 == "Agree"
replace ai12 = 6 if antiint_1_2 == "Strongly agree"
tab antiint_1_3
gen ai13 = .
replace ai13 = . if antiint_1_3 == "NA"
replace ai13 = 6 if antiint_1_3 == "Strongly disagree"
replace ai13 = 5 if antiint_1_3 == "Disagree"
replace ai13 = 4 if antiint_1_3 == "Slightly disagree"
replace ai13 = 3 if antiint_1_3 == "Neither agree nor disagree"
replace ai13 = 2 if antiint_1_3 == "Slightly agree"
replace ai13 = 1 if antiint_1_3 == "Agree"
replace ai13 = 0 if antiint_1_3 == "Strongly agree"

/// Three-Question Anti-Intellectualism (randomly assigned first)
egen antiintx1 = rmean(ai11 ai12 ai13)
gen ai1 = antiintx1/6
tab ai1
hist ai1
corr ai13 ai12 ai11
alpha ai13 ai12 ai11

/// Two-Question Anti-Intellectualism (randomly assigned first)
egen antiintalt1 = rmean(ai11 ai12)
gen ai1_alt = antiintalt1/6
tab ai1_alt
alpha ai11 ai12

/// Anti-Intellectualism: randomly assigned second
tab antiint_2_1
gen ai21 = .
replace ai21 = . if antiint_2_1 == "NA"
replace ai21 = 0 if antiint_2_1 == "Strongly disagree"
replace ai21 = 1 if antiint_2_1 == "Disagree"
replace ai21 = 2 if antiint_2_1 == "Slightly disagree"
replace ai21 = 3 if antiint_2_1 == "Neither agree nor disagree"
replace ai21 = 4 if antiint_2_1 == "Slightly agree"
replace ai21 = 5 if antiint_2_1 == "Agree"
replace ai21 = 6 if antiint_2_1 == "Strongly agree"
tab antiint_2_2
gen ai22 = .
replace ai22 = . if antiint_2_2 == "NA"
replace ai22 = 0 if antiint_2_2 == "Strongly disagree"
replace ai22 = 1 if antiint_2_2 == "Disagree"
replace ai22 = 2 if antiint_2_2 == "Slightly disagree"
replace ai22 = 3 if antiint_2_2 == "Neither agree nor disagree"
replace ai22 = 4 if antiint_2_2 == "Slightly agree"
replace ai22 = 5 if antiint_2_2 == "Agree"
replace ai22 = 6 if antiint_2_2 == "Strongly agree"
tab antiint_2_3
gen ai23 = .
replace ai23 = . if antiint_2_3 == "NA"
replace ai23 = 6 if antiint_2_3 == "Strongly disagree"
replace ai23 = 5 if antiint_2_3 == "Disagree"
replace ai23 = 4 if antiint_2_3 == "Slightly disagree"
replace ai23 = 3 if antiint_2_3 == "Neither agree nor disagree"
replace ai23 = 2 if antiint_2_3 == "Slightly agree"
replace ai23 = 1 if antiint_2_3 == "Agree"
replace ai23 = 0 if antiint_2_3 == "Strongly agree"

/// Three-Question Anti-Intellectualism (randomly assigned second)
egen antiintx2 = rmean(ai21 ai22 ai23)
gen ai2 = antiintx2/6
tab ai2
hist ai2
corr ai23 ai22 ai21
alpha ai23 ai22 ai21
egen antiintalt2 = rmean(ai21 ai22)
gen ai2_alt = antiintalt2/6
tab ai2_alt
alpha ai21 ai22

/// Two-Question Anti-Intellectualism (randomly assigned second)
gen antii1 = ai11
replace antii1 = ai21 if antii1 == .
gen antii2 = ai12
replace antii2 = ai22 if antii2 == .
gen antii3 = ai13
replace antii3 = ai23 if antii3 == .
alpha antii1 antii2 antii3
alpha antii1 antii2

tabstat ai1_alt, stat(mean)
tabstat ai2_alt, stat(mean)
tabstat ai1_alt if ruca1 > 1, stat(mean)
tabstat ai2_alt if ruca1 > 1, stat(mean)
tabstat ai1_alt if rural == 1, stat(mean)
tabstat ai2_alt if rural == 1, stat(mean)
tabstat ai1, stat(mean)
tabstat ai2, stat(mean)
tabstat ai1 if ruca1 > 1, stat(mean)
tabstat ai2 if ruca1 > 1, stat(mean)
tabstat ai1 if rural == 1, stat(mean)
tabstat ai2 if rural == 1, stat(mean)


//// All anti-intellecualism (three-question)
gen ai_all = .
replace ai_all = ai1 if ai1 !=.
replace ai_all = ai2 if ai2 !=.
tab ai_all
//// All anti-intellecualism (two-question)
gen ai_allalt = .
replace ai_allalt = ai1_alt if ai1 !=.
replace ai_allalt = ai2_alt if ai2 !=.
tab ai_allalt



///// Rural Identity Questions (randomly first)
tab rurid_1_1
gen rurid11 = .
replace rurid11 = . if rurid_1_1 == "NA"
replace rurid11 = 0 if rurid_1_1 == "None at all"
replace rurid11 = 1 if rurid_1_1 == "A little"
replace rurid11 = 2 if rurid_1_1 == "A moderate amount"
replace rurid11 = 3 if rurid_1_1 == "A lot"
replace rurid11 = 4 if rurid_1_1 == "A great deal"

tab rurid_1_2
gen rurid12 = .
replace rurid12 = . if rurid_1_2 == "NA"
replace rurid12 = 4 if rurid_1_2 == "Extremely important"
replace rurid12 = 3 if rurid_1_2 == "Very important"
replace rurid12 = 2 if rurid_1_2 == "Moderately important"
replace rurid12 = 1 if rurid_1_2 == "Slightly important"
replace rurid12 = 0 if rurid_1_2 == "Not at all important"

tab rurid_1_3
gen rurid13 = .
replace rurid13 = . if rurid_1_3 == "NA"
replace rurid13 = 4 if rurid_1_3 == "Extremely well"
replace rurid13 = 3 if rurid_1_3 == "Very well"
replace rurid13 = 2 if rurid_1_3 == "Moderately well"
replace rurid13 = 1 if rurid_1_3 == "Slightly well"
replace rurid13 = 0 if rurid_1_3 == "Not well at all"

alpha rurid11 rurid12 rurid13
egen ruridfull = rmean(rurid11 rurid12 rurid13)
tab ruridfull
gen rurid1 = ruridfull/4

///// Rural Identity Questions (randomly second)
tab rurid_2_1
gen rurid21 = .
replace rurid21 = . if rurid_2_1 == "NA"
replace rurid21 = 0 if rurid_2_1 == "None at all"
replace rurid21 = 1 if rurid_2_1 == "A little"
replace rurid21 = 2 if rurid_2_1 == "A moderate amount"
replace rurid21 = 3 if rurid_2_1 == "A lot"
replace rurid21 = 4 if rurid_2_1 == "A great deal"

tab rurid_2_2
gen rurid22 = .
replace rurid22 = . if rurid_2_2 == "NA"
replace rurid22 = 4 if rurid_2_2 == "Extremely important"
replace rurid22 = 3 if rurid_2_2 == "Very important"
replace rurid22 = 2 if rurid_2_2 == "Moderately important"
replace rurid22 = 1 if rurid_2_2 == "Slightly important"
replace rurid22 = 0 if rurid_2_2 == "Not at all important"

tab rurid_2_3
gen rurid23 = .
replace rurid23 = . if rurid_2_3 == "NA"
replace rurid23 = 4 if rurid_2_3 == "Extremely well"
replace rurid23 = 3 if rurid_2_3 == "Very well"
replace rurid23 = 2 if rurid_2_3 == "Moderately well"
replace rurid23 = 1 if rurid_2_3 == "Slightly well"
replace rurid23 = 0 if rurid_2_3 == "Not well at all"

///// Rural Identity Scale
alpha rurid21 rurid22 rurid23
egen ruridfullx = rmean(rurid21 rurid22 rurid23)
tab ruridfullx
gen rurid2 = ruridfullx/4
drop ruridfull
drop ruridfullx

gen rasocid1 = rurid21
replace rasocid1 = rurid11 if rasocid1==.
gen rasocid2 = rurid22
replace rasocid2 = rurid12 if rasocid2 ==.
gen rasocid3 = rurid23
replace rasocid3 = rurid13 if rasocid3 ==.
tab rasocid1 rurid11
alpha rasocid1 rasocid2 rasocid3

tabstat rurid1, stat(mean)
tabstat rurid2, stat(mean)
tabstat rurid1 if rural==1, stat(mean)
tabstat rurid2 if rural==1, stat(mean)
tabstat rurid1 if ruca1 > 1, stat(mean)
tabstat rurid2 if ruca1 > 1, stat(mean)

gen rurid_all = .
replace rurid_all = rurid1 if rurid1 != .
replace rurid_all = rurid2 if rurid2 != .
tab rurid_all

gen ai_all = .
replace ai_all = ai1 if ai1 !=.
replace ai_all = ai2 if ai2 !=.
tab ai_all

gen ai_allalt = .
replace ai_allalt = ai1_alt if ai1 !=.
replace ai_allalt = ai2_alt if ai2 !=.
tab ai_allalt

corr rurid_all ai_all
corr rucarural ai_all
corr rural ai_all


/// Rural residency
gen rural = 0
replace rural = 1 if lq1 == "Rural"
replace rural = 1 if lq1 == "Small Town"
replace rural = 1 if lq2 == "Rural"
replace rural = 1 if lq2 == "Small Town"



////////////////////////////////////////////////
////// EXP RESULTS ///////////////////////////
//////////////////////////////////////////////////

/// Means for rural residents (self id)
by rurexp, sort: tabstat ai_all if rural==1
by rurexp, sort: tabstat ai_allalt if rural==1
ttest ai_allalt if rural==1, by(rurexp)
ttest ai_all if rural==1, by(rurexp)

ttest ai_all, by(rurexp)
ttest ai_allalt, by(rurexp)

/// correlations
corr rural ai_all
corr rural ai_allalt

/// manipulation check: order had no effect (can't reject null hypotheses)
tabstat rurid_all if rurexp ==0 & order == 0, stat(mean)
tabstat rurid_all if rurexp ==0 & order == 1, stat(mean)
ttest rurid_all if rurexp==0, by(order)
ttest ai_all if rurexp==0, by(order)
ttest ai_allalt if rurexp==0, by(order)


tabstat ai_all if order==0 & rurexp==0, stat(mean)
tabstat ai_all if order==1 & rurexp==0, stat(mean)
tabstat ai_allalt if order==0 & rurexp==0, stat(mean)
tabstat ai_allalt if order==1 & rurexp==0, stat(mean)
tabstat rurid_all if order==0 & rurexp==0, stat(mean)
tabstat rurid_all if order==1 & rurexp==0, stat(mean)
ttest rurid_all, by(order)
tabstat rurid_all if order==0, stat(mean)
tabstat rurid_all if order == 1, stat(mean)
tabstat ai_all if order == 1, stat(mean)
tabstat ai_all if order == 0, stat(mean)

reg ai_all i.order##c.rurid_all
margins, at(order=(0 1) ai_all=(0 1))
marginsplot
reg rurid_all i.order##c.ai_all
margins, at(order=(0 1) ai_all=(0 1))
marginsplot




///////////// Regression table in appendix

reg ai_all rurid_all rural rep dem conservative liberal age2 female edu1 black hisp inc
coefplot, drop(_cons inc hisp black edu1 female age2) scheme(s1mono) xline(0) ///
coeflabels(rurid_all = "Rural ID Strength" rural = "Rural Resident" dem = "Democrat" rep = "Republican" conservative = "Conservative" liberal = "Liberal")




